package com.cjy.discuss.controller;

import com.cjy.discuss.entity.Comment;
import com.cjy.discuss.service.CommentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;


@Controller
public class CommentController {
    @Resource
    private CommentService commentService;


    @GetMapping("/findAll")
    public String findAll(Model model) {
        model.addAttribute("list",commentService.findAll());
        return "commentList";
    }


    @GetMapping("/delOne")
    public String delOne(String id) {

        commentService.deleteComment(id);
        return "redirect:/findAll";
    }

    @PostMapping("/save")
    public String add(Comment comment) {
        commentService.save(comment);
        return "redirect:/findAll";
    }
    @PostMapping("/update")
    public String update(@RequestBody Comment comment) {
        commentService.updateComment(comment);
        return "redirect:/findAll";
    }

}
